/**
 * Created by Administrator on 2017/08/16 .
 */

'use strict';
var React = require('react-native');
var esptouchManager = React.NativeModules.UtilManager;

class UtilManager {


    getWifiConnectedSsid() {
        return new Promise((fulfill, reject) => {
            esptouchManager.getWifiConnectedSsid((error, data) => {
                if (error) {
                    reject(error);
                } else {
                    fulfill(data);
                }
            });
        });
    }

    receiveSpecLenByte(port, timeout, expectDataLen) {
        return new Promise((fulfill, reject) => {
            esptouchManager.receiveSpecLenByte(port, timeout, expectDataLen, (error, data) => {
                if (error) {
                    reject(error);
                } else {
                    fulfill(data);
                }
            });
        });
    }

    createFileWithByte(hexStr, fileName) {
        return new Promise((fulfill, reject) => {
            esptouchManager.createFileWithByte(hexStr, fileName, (error, data) => {
                if (error) {
                    reject(error);
                } else {
                    fulfill(data);
                }
            });
        });
    }

    performClick(x, y) {
        return new Promise((fulfill, reject) => {
            esptouchManager.performClick(x, y, (error, data) => {
                if (error) {
                    reject(error);
                } else {
                    fulfill(data);
                }
            });
        });
    }


}
module.exports = new UtilManager();
